package roborally.script.singleCommand;

import roborally.model.Energy;
import roborally.model.Robot;
import roborally.script.SingleCommand;
import be.kuleuven.cs.som.annotate.*;
import be.kuleuven.cs.som.taglet.*;

/**
 * @author Joren VERSPEURT
 * @author Mathieu REYMOND
 * @version 3.0
 * 
 * The class representing a Move command. When stepped it will move its Robot.
 */
public class Move extends SingleCommand {
	
	/**
	 * Create a new Move command.
	 * @param robot The Robot this Move command will apply to.
	 */
	public Move(Robot robot) {
		super(robot);
	}
	
	/**
	 * Try to move <code>getRobot()</code> one step forward. If this fails prints a message.
	 */
	@Override
	public void step(){
		super.step();
		
		if(robot.getEnergy().getValueIn(Energy.Unit.WS) >= Robot.getEnergyRequiredToMove().getValueIn(Energy.Unit.WS)+robot.getLoad()*Robot.getLoadFactor()) {
			
			try {
				robot.move();
			}
			catch(Exception e) {
				System.out.println(e.getMessage());
			}
		}
	}
	
	/**
	 * The script word for this command.
	 */
	@Override
	public String toString() {
		return "move";
	}
}
